﻿#include "CRC16.h"

uint16_t CRC16_CCITT(const uint8_t* data, size_t length, uint16_t crc)
{
    for (size_t i = 0; i < length; ++i) {
        crc ^= (uint16_t)data[i] << 8;
        for (int j = 0; j < 8; ++j) {
            if (crc & 0x8000)
                crc = (crc << 1) ^ 0x1021;
            else
                crc <<= 1;
        }
    }
    return crc;
}
